#ifndef _BOARD_H_
#define _BOARD_H_

#include "../head_file.h"
#include "./chip/chip.h"
#include "./advanced_cfg/advanced_cfg.h"
#include "../control.h"
#include "../key.h"

typedef INT32 (*SNimAttach)(struct QPSK_TUNER_CONFIG_API *ptrQPSK_Tuner); 
typedef INT32 (*CNimAttach)(struct QAM_TUNER_CONFIG_API *ptrQAM_Tuner); 
typedef INT32 (*TNimAttach)(struct COFDM_TUNER_CONFIG_API *ptrCOFDM_Tuner); 
typedef INT32 (*TNimAttactWithName)(char *name, PCOFDM_TUNER_CONFIG_API pConfig);

typedef INT32 (*ScartAttach)(struct scart_init_param * param);
typedef void (*PanI2cIdSet)(struct pan_device *dev, UINT32 i2c_id);
typedef INT32 (*PanAttach)(struct pan_configuration *config);
typedef INT32 (*RfmAttach)(void);

typedef struct
{
    UINT32 sci_id;
    UINT32 bps;    
    UINT32 sci_parity;
}SciCfg;

typedef struct 
{
    UINT32 i2c_id;
    UINT32 bps;
    UINT32 en;
    GpioInfo* sda;
    GpioInfo* scl;
}I2cCfg;

typedef struct 
{
    UINT8 tsi_id;
    UINT8 tsi_attr;
    UINT8 tsi_spi_tsg_attr;
    UINT8 tsi_select;  // this thi_id connect to TSI_TS_A or TSI_TS_B    
}TsiCfg;

typedef struct 
{
    struct QPSK_TUNER_CONFIG_API qpsk_tuner;
    SNimAttach   attach;
    UINT8 tsi_id_m3501a;
    UINT8 tsi_attr_m3501a;
}SNimCfg;

typedef struct 
{
	struct QAM_TUNER_CONFIG_API qam_tuner;
    CNimAttach  attach;
    GpioInfo* qam_int;    
}CNimCfg;

typedef struct 
{  
    struct COFDM_TUNER_CONFIG_API cofdm_tuner;
    TNimAttach attach;
    TNimAttactWithName attach_with_name;
}TNimCfg;


typedef union 
{
    SNimCfg  s_cfg;
    CNimCfg  c_cfg;
    TNimCfg  t_cfg;
}NimCfg;

typedef struct 
{  
    UINT8 front_end_type;  // FRONTEND_TYPE_S FRONTEND_TYPE_C FRONTEND_TYPE_T 
    UINT8 is_isdbt;         
    UINT16 sat_id;         // if front_end_type == FRONTEND_TYPE_C/FRONTEND_TYPE_T then, 
                           // all this type program will be linked with this sat.
                           // if front_end_type == FRONTEND_TYPE_S  then,
                           // all dvbs program will use satellite with sat id(from sat_id to MAX_SAT_NUM-1)
    char* nim_name;
    TsiCfg tsi_cfg;
    GpioInfo* nim_reset;
    GpioInfo* lnb_power;
    GpioInfo* lnb_short_det;
    NimCfg nim_config;
	GpioInfo* antenna_power;
}FrontEndCfg;


typedef struct
{
    //pinmux gpio
    UINT8 pin_mux_count;
    UINT8 all_gpio_count;       //for easy init all gpio    
    BOOL mem_gpio_enabled;        
    PinMuxInfo* pin_mux_array; 
    GpioInfo* all_gpio_array;   //for easy init all gpio


    GpioInfo* ddr_power_ctl;
    GpioInfo* sys_power;
    GpioInfo* mute;
    GpioInfo* usb_power;
    GpioInfo* fp_standby;   //turn off/on standby led
    GpioInfo* fp_standby_key;   //GPIO standby key on panel.
    GpioInfo* scart_tvsat_switch;
    GpioInfo* scart_aspect;
    GpioInfo* scart_tv_fb;
    GpioInfo* scart_power;
    GpioInfo* scart_vcr_switch; 
    GpioInfo* scart_vcr_detech;  //POS_SCART_VCR_DETECT
    GpioInfo* smc_5v_ctl;
    GpioInfo* ata2lan_cs;
    GpioInfo* sdio_detect;
    GpioInfo* sdio_lock;
    GpioInfo* sdio_cs;
    //GpioInfo* sdio_polor;
    
    //frontend;
    FrontEndCfg* front_end_cfg[2];
    
    //SCI
    UINT8 libc_printf_uart_id;
    SciCfg* sci_config[2];
    
    //i2c
    I2cCfg* i2c_config[6];
    UINT8 i2c_gpio_num;
    UINT8 i2c_scb_num;

    //scart
    struct scart_init_param * scart_param;
    ScartAttach scart_attach;

    //panel
    struct pan_configuration* pan_config;
    PanI2cIdSet pan_i2c_id_set;
    PanAttach pan_attach;
    UINT32 pan_i2c_id;

    //flash
    UINT8 flash_type; // 0 sflash, 1 pflash

    //rfm
    RfmAttach rfm_attach;
    UINT8 rfm_i2c_id;            //#define I2C_FOR_RFM   I2C_TYPE_GPIO0

    //chip
    ChipInitParam chip_param;    
    //board advance cfg
    AdvanceCfgPara adv_cfg_para;

    //key map
    UINT32 key_map_cnt;
    const struct ir_key_map_t *key_map;
    IR_Key_Map_t *ir_key_maps;
}BoardCfg;



typedef enum
{
    POWER_OFF = 0,
    POWER_ON,
}PowerOnOff;



UINT32 board_get_frontend_type(UINT8 frontend_id);
UINT16 board_get_frontend_satid(UINT8 frontend_id);
UINT8  board_lnb_state(UINT8 frontend_id);               // 0: normal, 1: short deteched(overload)
void board_lnb_power(UINT8 frontend_id, BOOL sw);    // 0: 0ff 1: on
void board_antanne_power(UINT8 frontend_id, BOOL sw);
void board_frontend_reset(UINT8 frontend_id);
void board_power(BOOL sw);                           // 0: off 1: on          
#ifdef MULTI_CAS   
void board_class_select(enum class_selection cls_sel);
#endif
void board_sci_init();
void board_i2c_init();
void board_frontend_init();
void board_standby_led_onoff(BOOL onoff);
void board_usb_power(BOOL onoff);
void set_board_cfg(BoardCfg* cfg);
BoardCfg* get_board_cfg(void);

UINT8 board_frontend_is_isdbt(UINT8 frontend_id);

const struct ir_key_map_t* board_get_key_map(void);
UINT32 board_get_key_map_cnt(void);
IR_Key_Map_t* board_get_ir_key_map(void);

#endif

